package com.ykt.controller;

import com.jfinal.ext.route.ControllerBind;
import com.ykt.model.Service;

import java.util.Date;
import java.util.Random;

@ControllerBind(controllerKey="/service")
public class ServiceController extends BaseController<Service>{
	
	public ServiceController(){
		super(Service.class);
	}
	
	/**
	 * 修改状态
	 */
	public void audit() {
		String msg = "状态已变更";
		try {
			Service service = Service.dao.findById(getParaToInt(0));
			if(isParaExists(1)){
				service.set(Service.status, getPara(1));
				service.set(Service.updated_time, new Date());
			}else{
				String status = service.getStr(Service.status);
				service.set(Service.status, status);
			}
			service.update();
			int id = service.getInt("id");
			rendJson(true, msg, id, new Random().nextLong());
		} catch (Exception e) {
			log.error("保存异常", e);
			rendJson(false, "保存异常！");
			e.printStackTrace();
		}
	}
	
}
